package movee.spring.cloud.gateway.config;

import com.alibaba.csp.sentinel.slots.block.degrade.circuitbreaker.CircuitBreakerStrategy;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * sentinel配置
 *
 * @author 54740559@qq.com
 */
@Component
@ConfigurationProperties(prefix = "alibaba.sentinel")
@Data
public class SentinelProperties {

    private List<FlowRuleConfig> flowRules;
    private List<DegradeRuleConfig> degradeRules;

    /**
     * 限流
     */
    @Data
    public static class FlowRuleConfig {
        private String id;
        private List<String> resources;
        private Double count;
        private Long intervalSec;
    }

    /**
     * 降级
     */
    @Data
    public static class DegradeRuleConfig {
        private String id;
        private List<String> resources;
        private CircuitBreakerStrategy grade;
        private Double count;
        private Integer timeWindow;
        private Integer minRequestAmount;
        private Integer statIntervalMs;
        private Double slowRatioThreshold;
    }
}
